package com.gravata.enigma.repositorio.impl;

import java.sql.SQLException;
import java.util.List;

import android.content.Context;

import com.gravata.enigma.model.Profile;
import com.gravata.enigma.model.Satelite;
import com.gravata.enigma.model.Transponder;
import com.gravata.enigma.repositorio.RepositorioGenerico;
import com.gravata.enigma.repositorio.RepositorioSatelite;
import com.j256.ormlite.dao.ForeignCollection;

public class RepositorioSateliteImpl extends RepositorioGenerico<Satelite>
		implements RepositorioSatelite {

	public RepositorioSateliteImpl(Context context) throws SQLException {
		super(context);
	}

	@Override
	public ForeignCollection<Transponder> getEmptyCollection() {
		try {
			return database.getEmptyForeignCollection("transponders");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public void excluir(Profile profile) {
		List<Satelite> satelites=listar(profile);

		for(Satelite satelite: satelites){
			if(!satelite.getTransponders().isEmpty())
				satelite.getTransponders().clear();

			try {
				excluir(satelite);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}